using UnityEngine;

[ExecuteInEditMode]
public class ControllerCameraView : ControllerGeneric
{
	public float width = 1f;

	public float lenght = 1f;

	public float height = 1f;

	public GameObject cube;

	public CameraHorizontalFollowMode viewType;

	private bool staticState;

	public override void OnLevelInPlace(Transform levelTransform)
	{
		base.OnLevelInPlace(levelTransform);
		if (levelTransform == base.transform.root)
		{
			PrepareForGame();
		}
	}

	public void PrepareForGame()
	{
		SetNames();
		SetParenting();
		CameraViewTrigger component = cube.GetComponent<CameraViewTrigger>();
		if (component == null)
		{
			cube.AddComponent<CameraViewTrigger>();
		}
		component.cameraViewType = viewType;
		Object.Destroy(cube.GetComponent<Renderer>());
		Object.Destroy(cube.GetComponent<MeshFilter>());
		if (Application.isPlaying)
		{
			Object.Destroy(base.gameObject);
		}
		else
		{
			Object.DestroyImmediate(base.gameObject);
		}
	}

	private void Update()
	{
		if (!Application.isEditor || Application.isPlaying)
		{
			return;
		}
		SetupRemoteControl();
		if (IsRemoteControlActive())
		{
			base.transform.position = remoteControl.transform.position;
			base.transform.rotation = remoteControl.transform.rotation;
			height = remoteControl.transform.localScale.y;
			width = remoteControl.transform.localScale.x;
			lenght = remoteControl.transform.localScale.z;
		}
		if (height < 0.0001f)
		{
			height = 0.0001f;
		}
		if (width < 0.0001f)
		{
			width = 0.0001f;
		}
		if (lenght < 0.0001f)
		{
			lenght = 0.0001f;
		}
		if (remoteControl != null)
		{
			if (remoteControl.manualScale)
			{
				remoteControl.scale = new Vector3(remoteControl.scale.x, remoteControl.scale.y, remoteControl.scale.z);
			}
			else
			{
				remoteControl.transform.localScale = new Vector3(width, height, lenght);
			}
		}
		Setup();
	}

	private void Setup()
	{
		AssureParenting();
		cube.transform.localPosition = Vector3.zero;
		cube.transform.localEulerAngles = Vector3.zero;
		cube.transform.localScale = new Vector3(width, height, lenght);
	}

	private void SetStatic(bool newStaticState = true)
	{
		if (newStaticState != staticState)
		{
			staticState = newStaticState;
			cube.isStatic = staticState;
		}
	}

	private void SetParenting()
	{
		cube.transform.parent = base.transform.parent;
	}

	private void SetNames()
	{
		cube.name = "CameraViewSwitch";
	}

	public void SetupRemoteControl()
	{
		if (remoteControl == null)
		{
			InitRemoteControl();
			remoteControl.gameObject.name = remoteControl.gameObject.name + base.name;
			remoteControl.gameObject.transform.position = base.transform.position;
			remoteControl.gameObject.transform.rotation = base.transform.rotation;
			remoteControl.gameObject.transform.localScale = new Vector3(width, height, lenght);
			remoteControl.gameObject.AddComponent<PresetsCameraView>();
		}
	}

	public override void CopyFromRemoteControl(RemoteControl rc)
	{
		base.CopyFromRemoteControl(rc);
		CopyParentingFromRemoteControl(rc);
	}
}
